#ifndef CVX_STEREO_INTRINSIC_SOLVER_H
#define CVX_STEREO_INTRINSIC_SOLVER_H

/*
	recover shading map and reflectance map from a stereo image 
*/

#include "cvxImage.h"
#include "cvxAdaptiveQuadTree.h"
#include "cvxIntrinsicSolver.h"


class CvxStereoIntrinsicSolver
{
public:
	CvxStereoIntrinsicSolver();
	~CvxStereoIntrinsicSolver();

	void setImage(const Mat &leftImage, const Mat &rightImage, float threshold = 0.999);

	// large node and single pixel node are known
	bool SetETree(const int stddevThreshold, const int sizeThrehold = 16);
	//shading map 0.0: unknown area, other is known
	//threshold is deviation of color to divide quadtree
	bool SetETree(const Mat &leftInitialShadingMap, const Mat &rightInitialShadingMap, const int threshold = 5);	
	bool SolveETree(bool useEdge, bool useMatch = false, bool test = false);	
	bool CalcMTree(bool reverse);
	bool SolveMtree(bool useEdge, bool test = false);
	//up sample using A vector to get final result
	bool UpsampleAvector(bool test = false);

	//   match similar node in the left and right image
	bool MatchLeftRightETree(float rgbThreshold, const int sizeThreshold = 4, bool isShow = false);


private:
	CvxAdaptiveQuadTree *m_leftETree;  //solve unknown area of local solver result
	CvxAdaptiveQuadTree *m_leftMTree;  //refine known area
	CvxAdaptiveQuadTree *m_rightETree;
	CvxAdaptiveQuadTree *m_rightMTree;

	CvxIntrinsicSolver *m_leftIntrinsicData;   //only store data
	CvxIntrinsicSolver *m_rightIntrinsicData;  //only store data

	bool upSampleAvectorInOneTree(CvxAdaptiveQuadTree * const mTree, CvxIntrinsicSolver * const intrinsicData, bool test);

	

};
#endif